package com.example.hemin.fnb.ui.presenter;

import android.content.Context;

import com.example.hemin.fnb.ui.base.BasePresenter;
import com.example.hemin.fnb.ui.bean.BaseObjectBean;
import com.example.hemin.fnb.ui.bean.MessageBean1;
import com.example.hemin.fnb.ui.bean.MessageBean2;
import com.example.hemin.fnb.ui.bean.MessageBean3;
import com.example.hemin.fnb.ui.bean.MessageImageBean;
import com.example.hemin.fnb.ui.bean.MessageImages;
import com.example.hemin.fnb.ui.contract.MessageContract;
import com.example.hemin.fnb.ui.fragment.MessageFragment;
import com.example.hemin.fnb.ui.fragment.TabMessageFragment;
import com.example.hemin.fnb.ui.model.MessageModle;
import com.example.hemin.fnb.ui.net.RxScheduler;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;
import java.util.Map;

import io.reactivex.functions.Consumer;

public class MessagePresenter extends BasePresenter<MessageFragment>  implements MessageContract.Presenter {
    private MessageContract.modle1 modle1;
    private MessageContract.modle2  modle2;
    private MessageContract.modle3 modle3;
    private MessageContract.modle4 modle4;
    public  MessagePresenter(){
        modle1 = new MessageModle();
        modle2 = new MessageModle();
        modle3 = new MessageModle();
        modle4 = new MessageModle();
    }


    @Override
    public void getMaga(Context context, Map token, long current, long size, String type, final int status) {
        if(!isViewAttached()){
            return;
        }
        String data1 = "{\"total\":1,\"size\":10,\"pages\":1,\"current\":1,\"records\":[{\"magazineId\":1,\"magazineName\":\"玩瓷人群的三个层次\",\"magazineStage\":\"第一期\",\"magazineUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/65sfwkdgbx\",\"updateTime\":\"2019-05-27 09:46:06\",\"nickname\":\"test\"}]}";
        Gson gson = new Gson();
        MessageBean1 bean1 = gson.fromJson(data1,new TypeToken<MessageBean1>(){}.getType());
        MessageBean1.DataBean bean12 = bean1.getData();
        mView.Date(bean12,status);
//        mView.showLoading();
//        modle1.getMaga(context, token,current,size,type)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
//                        mView.hideLoading();
//                        MessageBean1.DataBean bean1 = (MessageBean1.DataBean) bean.getResult();
//                        List<MessageBean1.DataBean.RecordsBean> list = bean1.getRecords();
//                        mView.Date(list,status);
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
//                        mView.hideLoading();
//                    }
//                });
    }

    @Override
    public void getTuiJian(Context context, Map token, long current, long size, int userId, final int status) {
        if(!isViewAttached()){
            return;
        }
        String data2 ="{\"data\":{\"total\":11,\"size\":1,\"pages\":11,\"current\":1,\"records\":[{\"friendId\":11,\"friendHead\":\"啦啦啦\",\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/20190529111710.jpeg\",\"userUrl\":\"https://funwl.oss-cn-hangzhou.aliyuncs.com/images/u%3D1229021758%2C2220622610%26fm%3D27%26gp%3D0.jpg\",\"nickname\":\"137****0107\",\"giveNum\":1,\"isGiveNum\":0,\"roleId\":3}]}}";
        Gson gson = new Gson();
        MessageBean2 bean2 = gson.fromJson(data2,new TypeToken<MessageBean2>(){}.getType());
        MessageBean2.DataBean beans =  bean2.getData();
        List<MessageBean2.DataBean.RecordsBean> list = beans.getRecords();
        mView.Date(list,status);

//        mView.showLoading();
//        modle2.getTuiJian(context, token,current,size,userId)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
////                        mView.hideLoading();
//                        MessageBean2.DataBean bean2 = (MessageBean2.DataBean) bean.getResult();
//                        List<MessageBean2.DataBean.RecordsBean> list = bean2.getRecords();
//                        mView.Date(list,status);
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
////                        mView.hideLoading();
//                    }
//                });
    }

    @Override
    public void getGuanZhu(Context context, Map token, long current, long size, int userId, final int status) {
        if(!isViewAttached()){
            return;
        }
        String data3 = "{\"data\":{\"records\" : [{\"friendId\":3,\"friendHead\":\"123456\",\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/ygcnxwu528\",\"userUrl\":\"https://funwl.oss-cn-hangzhou.aliyuncs.com/images/u%3D1229021758%2C2220622610%26fm%3D27%26gp%3D0.jpg\",\"nickname\":\"jkl\",\"giveNum\":1,\"isGiveNum\":0,\"roleId\":2},{\"friendId\":4,\"friendHead\":\"测试\",\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/6ra8sgwlqv\",\"userUrl\":\"https://funwl.oss-cn-hangzhou.aliyuncs.com/images/u%3D1229021758%2C2220622610%26fm%3D27%26gp%3D0.jpg\",\"nickname\":\"173****4861\",\"giveNum\":2,\"isGiveNum\":0,\"roleId\":2},{\"friendId\":1,\"friendHead\":\"asdasd\",\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/u7b3h9r8sn\",\"userUrl\":\"https://funwl.oss-cn-hangzhou.aliyuncs.com/images/u%3D1229021758%2C2220622610%26fm%3D27%26gp%3D0.jpg\",\"nickname\":\"jkl\",\"giveNum\":2,\"isGiveNum\":0,\"roleId\":2},{\"friendId\":2,\"friendHead\":\"dssad\",\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/y2nkmtl9ru\",\"userUrl\":\"https://funwl.oss-cn-hangzhou.aliyuncs.com/images/u%3D1229021758%2C2220622610%26fm%3D27%26gp%3D0.jpg\",\"nickname\":\"jkl\",\"giveNum\":2,\"isGiveNum\":0,\"roleId\":2}]}}";
//        mView.showLoading();
        Gson gson = new Gson();
        MessageBean3 bean3 = gson.fromJson(data3,new TypeToken<MessageBean3>(){}.getType());
        MessageBean3.DataBean beans =  bean3.getData();
        List<MessageBean3.DataBean.RecordsBean> bean3s =  beans.getRecords();
        mView.Date(bean3s,status);
//        modle3.getGuanZhu(context, token,current,size,userId)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
////                        mView.hideLoading();
//                        MessageBean3.DataBean bean3 = (MessageBean3.DataBean) bean.getResult();
//                        List<MessageBean3.DataBean.RecordsBean> list = bean3.getRecords();
//                        mView.Date(list,status);
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
////                        mView.hideLoading();
//                    }
//                });
    }

    @Override
    public void getFidner(Context context, Map token, long friendId, final int userId) {
        if(!isViewAttached()){
            return;
        }
        String data4 = "{\"data\" : {\"friendId\":null,\"userId\":\"17\",\"userUrl\":\"https://funwl.oss-cn-hangzhou.aliyuncs.com/images/u%3D1229021758%2C2220622610%26fm%3D27%26gp%3D0.jpg\",\"nickname\":\"137****0107\",\"friendContent\":\"啦啦啦\",\"images\":[{\"imagesUrl\":\"https://wan-jian.oss-cn-hangzhou.aliyuncs.com/images/20190529111710.jpeg\"}],\"giveNum\":1,\"isGiveNum\":2,\"isCollectionSum\":2}}";
        Gson gson = new Gson();
        MessageImageBean bean4 = gson.fromJson(data4,new TypeToken<MessageImageBean>(){}.getType());
        MessageImageBean.DataBean bean1 = (MessageImageBean.DataBean) bean4.getData();
        List<MessageImageBean.DataBean.ImagesBean> list = bean1.getImages();
        String userid = bean1.getUserId();
        String contnet = bean1.getFriendContent();
        String urlImage = bean1.getUserUrl();
        String nickName = bean1.getNickname();
        String isCollectionSum = bean1.getIsCollectionSum();
        String isGiveNum = bean1.getIsGiveNum();
        String isFocus = bean1.getIsFocus();
        int focusNum = bean1.getFocusNum();
        int giveNum = bean1.getGiveNum();

        mView.DateUserId(list,userid,contnet,urlImage,nickName,isCollectionSum,isGiveNum,isFocus,focusNum,giveNum);
//        mView.showLoading();
//        modle4.getFidner(context, token,friendId,userId)
//                .compose(RxScheduler.<BaseObjectBean>Flo_io_main())
//                .as(mView.<BaseObjectBean>bindAutoDispose())
//                .subscribe(new Consumer<BaseObjectBean>() {
//                    @Override
//                    public void accept(BaseObjectBean bean) throws Exception {
//                        mView.onSuccess(bean);
//                        mView.hideLoading();
//                        MessageImageBean.DataBean bean1 = (MessageImageBean.DataBean) bean.getResult();
//                        List<MessageImageBean.DataBean.ImagesBean> list = bean1.getImages();
//                        String userid = bean1.getUserId();
//                        String contnet = bean1.getFriendContent();
//                        String urlImage = bean1.getUserUrl();
//                        String nickName = bean1.getNickname();
//                        String isCollectionSum = bean1.getIsCollectionSum();
//                        String isGiveNum = bean1.getIsGiveNum();
//                        String isFocus = bean1.getIsFocus();
//                        int focusNum = bean1.getFocusNum();
//                        int giveNum = bean1.getGiveNum();
//
//                        mView.DateUserId(list,userid,contnet,urlImage,nickName,isCollectionSum,isGiveNum,isFocus,focusNum,giveNum);
//                    }
//                }, new Consumer<Throwable>() {
//                    @Override
//                    public void accept(Throwable throwable) throws Exception {
//                        mView.onError(throwable);
//                        mView.hideLoading();
//                    }
//                });
    }
}
